# Maintainer: Alexey Pavlov <alexpux@gmail.com>

_realname=pdcurses
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
conflicts=("${MINGW_PACKAGE_PREFIX}-ncurses")
provides=("${MINGW_PACKAGE_PREFIX}-ncurses")
pkgver=3.4
pkgrel=1
pkgdesc="Curses library (mingw-w64)"
arch=('any')
url="http://pdcurses.sourceforge.net/"
license=("custom")
makedepends=("${MINGW_PACKAGE_PREFIX}-gcc")
depends=("${MINGW_PACKAGE_PREFIX}-gcc-libs")
options=('staticlibs' 'strip')
source=("https://downloads.sourceforge.net/pdcurses/PDCurses-${pkgver}.tar.gz"
        "mingw-pdcurses-3.4-build.patch")
sha256sums=('46ad8fd439e71d44819ea884d775ccbf653b9f8b1f7a418a0cce3a510aa2e64b'
            'ebfc91337530f735d8fa3664a1bb7b8e481a2003ab09f1c8c5454ca4ba5f228e')

prepare() {
  cd "${srcdir}/PDCurses-${pkgver}"
  patch -Np1 -i ${srcdir}/mingw-pdcurses-3.4-build.patch
}

build() {
  cd "${srcdir}/PDCurses-${pkgver}/win32"

  make -f mingwin32.mak \
    CC=${MINGW_PREFIX}/bin/gcc \
    LINK=${MINGW_PREFIX}/bin/gcc \
    STRIP=${MINGW_PREFIX}/bin/strip \
    WIDE=Y \
    UTF8=Y \
    DLL=Y
}

package() {
  cd "${srcdir}/PDCurses-${pkgver}"

  mkdir -p ${pkgdir}${MINGW_PREFIX}/{bin,include,lib}
  install win32/*.exe ${pkgdir}${MINGW_PREFIX}/bin/
  install win32/pdcurses.dll ${pkgdir}${MINGW_PREFIX}/bin/
  install win32/pdcurses.a ${pkgdir}${MINGW_PREFIX}/lib/libpdcurses.dll.a
  install win32/pdcurses.a ${pkgdir}${MINGW_PREFIX}/lib/libcurses.dll.a

  install -m 0644 curses.h panel.h term.h ${pkgdir}${MINGW_PREFIX}/include/
}
